<?php
class Job extends Controller {
	function Job() {
		parent::Controller();
	}

	function showAll() {
		$this->load->model('job_model');
		$data['title'] = 'Frool';
		$data['jobs'] = $this->job_model->readAll();
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/showAll', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function show($id) {
		$this->load->model('job_model');
		$data['title'] = 'Frool';
		$data['job'] = $this->job_model->read($id);
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/show', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function find() {
		$this->load->model('state_model');
		$data['title'] = 'Frool';
		$data['states'] = $this->state_model->readAll();
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/find', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function add() {
		$this->load->model('job_model');
		if ($this->input->post('Submit')) {
			$this->job_model->create();
			redirect('default/job/showAll');
		}
		$data['title'] = 'Frool';
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/add', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function edit($id) {
		$this->load->model('job_model');
		if ($this->input->post('Submit')) {
			$this->job_model->update($id);
			redirect('job/showAll');
		}
		$data['title'] = 'Frool';
		$data['job'] = $this->job_model->read($id);
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/edit', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function findByState($stateId) {
		$this->load->model('occupation_model');
		$data['title'] = 'Frool';
		$data['stateId'] = $stateId;
		$data['occupations'] = $this->occupation_model->readByStateId($stateId);
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/findByState', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function findByStateAndOccupation($stateId, $occupationId) {
		$this->load->model('job_model');
		$data['title'] = 'Frool';
		$data['jobs'] = $this->job_model->readByStateAndOccupationId($stateId, $occupationId);
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'job/findByStateAndOccupation', $data, true);
		$this->load->view($theme.'layout', $data);
	}
}
?>
